﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;
using KMFrame.Core;
using SzCourt.Logic.NBL.DBEntities;

namespace SzCourt.WebSite.manager
{
    public partial class facebook_replay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            if (!this.IsPostBack)
            {
                getInfo();
            }
        }

        //根据ID获取信息
        private void getInfo()
        {
            int _ID = string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : Convert.ToInt32(Request.QueryString["id"]);
            this.hdnIdeasBoxID.Value= _ID.ToString();

            //调用方法

            IdeasBox art = new IdeasBox();
            pIdeasBox result = (pIdeasBox)art.GetIdeasBox(_ID);

            if (result != null)
            {
                this.tdAddDateTime.InnerHtml = result.AddDateTime.ToString();
                this.tdAddUserID.InnerHtml = result.AddUserName;
                this.tdAnswerDept.InnerHtml = result.AnswerDept;
                this.tdQuestions.InnerHtml = result.Questions;
                this.txtAnswer.Value = result.Answer;
                switch (result.PublishType)
                {
                    case 0:
                        this.rdopt1.Checked = true;
                        break;
                    case 1:
                        this.rdopt2.Checked = true;
                        break;
                    case 2:
                        this.rdopt3.Checked = true;
                        break;
                    default:
                        this.rdopt1.Checked = true;
                        break;
                }
                
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!AdminSession.SessionBox.CheckUserSession())
            {
                Response.Redirect("/manager/login.aspx");
            }
            int Id = int.Parse(this.hdnIdeasBoxID.Value);
            string sessionUserName = AdminSession.SessionBox.GetUserSession().UserName;
            string content = this.txtAnswer.Value;
            short PublishType = short.Parse(Request.Form["rdoPublishType"].ToString());


            IdeasBox bll = new IdeasBox();
            bool result = (bool)bll.AnswerIndea(Id, sessionUserName, content, PublishType);

            if (result)
            {
                this.divMessage.InnerHtml = "回复成功！";
            }
            else
            {
                this.divMessage.InnerHtml = "回复失败！";
            }

        }
    }
}